package fileUtil;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

/**
 * @Author: WangYongGan
 * @Date: 2021/11/8 20:43
 * @Description:
 */
public class SaveHtml {
    static String html = "<!DOCTYPE html>\n" +
            "<html lang=\"en\">\n" +
            "<head>\n" +
            "    <meta charset=\"UTF-8\">\n" +
            "    <title>Title</title>\n" +
            "    <script src=\"js/jquery-3.5.1.js\"></script>\n" +
            "    <script>\n" +
            "        //发送异步请求\n" +
            "        function f(){\n" +
            "            var x;\n" +
            "            //核心对象\n" +
            "            if(window.XMLHttpRequest)\n" +
            "                x=new XMLHttpRequest()\n" +
            "            else x=new ActiveXObject(\"Micsoft.XMLHTTP\")\n" +
            "            //发送请求\n" +
            "            /*\n" +
            "             */\n" +
            "            x.open(\"get\",\"helloServlet?name=wang\",true)\n" +
            "            x.send()\n" +
            "        }\n" +
            "    </script>\n" +
            "    <script>\n" +
            "        // json对象格式\n" +
            "        // $.ajax({\n" +
            "        //     url:\" \",\n" +
            "        //     type:\"post\",\n" +
            "        //     data:JSON.stringify({\n" +
            "        //         adminId:adminId,\n" +
            "        //         password:password}),\n" +
            "        //     contentType: \"application/json;charset=UTF-8\",\n" +
            "        //     dataType:\"json\",\n" +
            "        //     success:function (data) {\n" +
            "        //\n" +
            "        //     }\n" +
            "        // });\n" +
            "        function ff(){\n" +
            "        console.log(\"发送请求\")\n" +
            "        $.ajax({\n" +
            "            url:\"http://114.55.253.244:8001/data/getDataOfPie\",\n" +
            "            type:\"post\",\n" +
            "            data: null,\n" +
            "            dataType:\"json\",\n" +
            "            success: function(data){\n" +
            "                console.log(data);\n" +
            "            },\n" +
            "            error:function (res){\n" +
            "                console.log(res)\n" +
            "            }\n" +
            "        });\n" +
            "        // 标准参数模式 “username=chen&nickname=alien”\n" +
            "        $.ajax({\n" +
            "            url:\"http://114.55.253.244:8001/data/getDataByDate\",\n" +
            "            type:\"post\",\n" +
            "            data:{\n" +
            "                \"begin\":\"2020-12-01\",\n" +
            "                \"end\":\"2020-12-05\"\n" +
            "            },\n" +
            "            dataType:\"json\",\n" +
            "            success: function(data){\n" +
            "                console.log(data);\n" +
            "            } ,error:function (res){\n" +
            "                console.log(res)\n" +
            "            }\n" +
            "        });}\n" +
            "    </script>\n" +
            "\n" +
            "</head>\n" +
            "<body>\n" +
            "<input type=\"button\" value=\"ajax请求\" onclick=\"ff()\">\n" +
            "<input>\n" +
            "<a>学号分别是:2021****48 2021****66</a><br>\n" +
            "<h3></h3>>\n" +
            "<img src=\"https://tse1-mm.cn.bing.net/th/id/OIP.GHZQPEmVGRTDasaumregFAHaEo?w=306&h=191&c=7&o=5&dpr=1.5&pid=1.7\"/>\n" +
            "</body>\n" +
            "</html>";

    public static void saveHtml(String s, String path) throws Exception {
        FileOutputStream fileOutputStream = new FileOutputStream(path);
        fileOutputStream.write(s.getBytes(StandardCharsets.UTF_8));
        FileOutputStream f2=new FileOutputStream("d:\\test.txt");
        f2=new FileOutputStream(String.valueOf(fileOutputStream));
        f2.close();
        fileOutputStream.close();
    }

    public static void readHtml(String path) throws Exception {
        BufferedReader bufferedReader=new BufferedReader(new FileReader(path));
        StringBuffer stringBuffer=new StringBuffer();
        String line;
        while ((line=bufferedReader.readLine())!=null){
            stringBuffer.append(line+"\n");
        }
        System.out.println(stringBuffer);
    }

    public static void main(String[] args) throws Exception {
        saveHtml(html,"../test1.html");
//        readHtml("../test1.html");
    }
}
